package com.rwaste.worker.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rwaste.commonutils.R;
import com.rwaste.worker.entity.DetailInfo;
import com.rwaste.worker.entity.Drawmoney;
import com.rwaste.worker.entity.vo.DetailListQuery;
import com.rwaste.worker.entity.vo.DrawListQuery;
import com.rwaste.worker.service.DrawmoneyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ly
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/worker/drawMoney")
public class DrawmoneyController {
    @Autowired
    private DrawmoneyService drawmoneyService;

    //多条件查询  详细信息
    @ApiOperation(value = "查询体现申请")
    @PostMapping("/findAllDrawMoney")
    public R findAllDetailInfo(@RequestBody DrawListQuery drawListQuery){
        Integer page = drawListQuery.getPage();
        Integer limit = drawListQuery.getLimit();


        String baseid = drawListQuery.getBaseid();
        Date creationTime = drawListQuery.getCreationTime();
        Integer form = drawListQuery.getForm();
        String id = drawListQuery.getId();


        QueryWrapper<Drawmoney> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(baseid)){
            wrapper.eq("baseid", baseid);
        }
        if(!StringUtils.isEmpty(form)){
            wrapper.eq("form", form);
        }
        if(!StringUtils.isEmpty(id)){
            wrapper.eq("id", id);
        }
        if(!StringUtils.isEmpty(creationTime)){
            wrapper.eq("creation_time", creationTime);
        }
        Page<Drawmoney> drawmoneyPage = new Page<>(page,limit);

        drawmoneyService.page(drawmoneyPage, wrapper);

        long total = drawmoneyPage.getTotal();
        List<Drawmoney> records = drawmoneyPage.getRecords();
        return R.ok().data("total",total).data("list",records);

    }


    @ApiOperation(value = "根据id 获取订单")
    @GetMapping("/findAppealDrawById/{id}")
    public R findAppealDrawById(@PathVariable String id){
        List<Drawmoney> list = drawmoneyService.findALLAppealDrawById(id);
        if (list.size()>0){
            return R.ok().data("list",list);
        };
        return R.error().message("没有数据");
    }

    @ApiOperation(value = "根据workerid 获取订单信息 和 分理员信息")
    @GetMapping("/findDAById/{id}")
    public R findDAById(@PathVariable String id){
        List list = drawmoneyService.findDAById(id);
        if (list.size()>0){
            return R.ok().data("list",list);
        };
        return R.error().message("没有数据");
    }


}

